from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
# Create your models here.


class Coupon(models.Model):
    code = models.CharField(max_length=50, unique=True, verbose_name='优惠券码')
    valid_from = models.DateTimeField(verbose_name='优惠券开始')
    valid_to = models.DateTimeField(verbose_name='优惠券失效')
    discount = models.IntegerField(validators=[MaxValueValidator(0), MaxValueValidator(100)], verbose_name='折扣率', default=0)
    discount_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='优惠金额', default=0)

    active = models.BooleanField(verbose_name='优惠券是否激活', default=False)

    class Meta:
        verbose_name = '优惠券'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
